package com.dyz.leetcode._08_StackAndQueue;

import java.util.ArrayDeque;

public class _739_dailyTemperatures {
    //单调递减栈
    public int[] dailyTemperatures(int[] temperatures) {
        ArrayDeque<Integer> stack = new ArrayDeque<>();
        int[] ans = new int[temperatures.length];
        for (int i=0; i<temperatures.length; i++){

            while (!stack.isEmpty() && temperatures[i]>temperatures[stack.peek()]){
                ans[stack.peek()] = i-stack.pop();

            }
            stack.push(i);
        }
        return ans;
    }

    public static void main(String[] args) {
        new _739_dailyTemperatures().dailyTemperatures(new int[]{73,74,75,71,69,72,76,73});
    }
}
